//
//  AppDelegate.m
//  wonderGroMoreDemo
//
//  Created by wonder2023 on 2024/3/20.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "WDBMS.h"
#import "WDGroMorePublic.h"
#import <WDGroMore/WDGroMorePublic.h>
#import <WDGroMore/WDGroMoreDelegateManager.h>

@interface AppDelegate ()<WDGroMoreAllDelegate>

// AppDelegate.h
@property (nonatomic, assign) BOOL isColdLaunch;

@end
ViewController * _viewController;

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.isColdLaunch = YES;

    CGRect bounds = [[UIScreen mainScreen] bounds];
    _window = [[UIWindow alloc] initWithFrame: bounds];

    _viewController = [[ViewController alloc]init];
    
#ifdef NSFoundationVersionNumber_iOS_7_0
    _viewController.automaticallyAdjustsScrollViewInsets = NO;
    _viewController.extendedLayoutIncludesOpaqueBars = NO;
    _viewController.edgesForExtendedLayout = UIRectEdgeAll;
#else
    _viewController.wantsFullScreenLayout = YES;
#endif
    
    [_window setRootViewController:_viewController];
    [_window makeKeyAndVisible];
    
    [[BMSAuthSDK shareInstance]initSDKCompletion:^(BOOL success, BOOL privacyAgreed, BOOL trackingAuthorized, BOOL didRealname, NSString * _Nonnull uuid) {
        if (privacyAgreed) {
            [WDGroMorePublic manager].uuid = uuid;
            
            [WDGroMorePublic manager].success = YES;
            
            [[WDGroMorePublic manager] GroMoreDelegate:self];
            
            [[WDGroMorePublic manager]initWindMillAdsWithNetworkDetection:YES];
            
            [[WDGroMorePublic manager]initAnalyticsSDK];
            [[WDGroMorePublic manager]WDApplication:application didFinishLaunchingWithOptions:launchOptions];

        }
    }];
    
    
    
    return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application {

    NSLog(@"【LIVE】->BecomeActive");
    [[WDGroMorePublic manager]WDApplicationWillEnterForeground:application];
    self.isColdLaunch = NO;
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"【LIVE】->WillEnterForeground");
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"【LIVE】->EnterBackground");
    [[WDGroMorePublic manager]WDApplicationDidEnterBackground:application];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"【LIVE】->WillTerminate");
    [[WDGroMorePublic manager]WDApplicationDidEnterBackground:application];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
    [[WDGroMorePublic manager]WDApplication:application openURL:url options:options];
    return YES;
}

- (void)WDGroMoreBannerAdDelegateWithClose:(nonnull BUNativeExpressBannerView *)bannerAd {
    NSLog(@"✅ [Banner] 广告关闭: %@", bannerAd);
}

- (void)WDGroMoreBannerAdShow:(nonnull BUNativeExpressBannerView *)bannerAd {
    NSLog(@"✅ [Banner] 广告展示成功: %@", bannerAd);
}

- (void)WDGroMoreConfig:(nonnull NSString *)userId {
    NSLog(@"✅ [GroMore] 配置完成，用户ID: %@", userId);
}

- (void)WDGroMoreIntersititialAdDelegateWithClose:(nonnull BUNativeExpressFullscreenVideoAd *)intersititialAd {
    NSLog(@"✅ [插屏] 广告关闭: %@", intersititialAd);
}

- (void)WDGroMoreIntersititialAdDidClickSkip:(nonnull BUNativeExpressFullscreenVideoAd *)intersititialAd {
    NSLog(@"⚠️ [插屏] 用户点击跳过广告: %@", intersititialAd);
}

- (void)WDGroMoreIntersititialAdDidPlayFinish:(nonnull BUNativeExpressFullscreenVideoAd *)intersititialAd didFailWithError:(nonnull NSError *)error {
    if (error) {
        NSLog(@"❌ [插屏] 播放失败: %@, 错误: %@", intersititialAd, error);
    } else {
        NSLog(@"✅ [插屏] 播放完成: %@", intersititialAd);
    }
}

- (void)WDGroMoreIntersititialAdDidShowFailed:(nonnull BUNativeExpressFullscreenVideoAd *)intersititialAd error:(nonnull NSError *)error {
    NSLog(@"❌ [插屏] 展示失败: %@，错误: %@", intersititialAd, error);
}

- (void)WDGroMoreIntersititialAdReady:(BOOL)ready {
    NSLog(@"ℹ️ [插屏] 广告准备状态: %@", ready ? @"✅ Ready" : @"❌ Not Ready");
}

- (void)WDGroMoreIntersititialAdShow:(nonnull BUNativeExpressFullscreenVideoAd *)intersititialAd {
    NSLog(@"✅ [插屏] 广告展示成功: %@", intersititialAd);
}

- (void)WDGroMoreNativeAdDidClose:(nonnull BUNativeAd *)nativeAd {
    NSLog(@"✅ [原生] 广告关闭: %@", nativeAd);
}

- (void)WDGroMoreNativeAdDidShow:(nonnull BUNativeAd *)nativeAd {
    NSLog(@"✅ [原生] 广告展示成功: %@", nativeAd);
}

- (void)WDGroMoreNativeAdDidShowFailed:(nonnull BUNativeAd *)nativeAd error:(nonnull NSError *)error {
    NSLog(@"❌ [原生] 展示失败: %@，错误: %@", nativeAd, error);
}

- (void)WDGroMoreRewardAdReady:(BOOL)ready {
    NSLog(@"ℹ️ [激励] 广告准备状态: %@", ready ? @"✅ Ready" : @"❌ Not Ready");
}

- (void)WDGroMoreRewardAdShow:(nonnull BUNativeExpressRewardedVideoAd *)rewardVideoAd {
    NSLog(@"✅ [激励] 广告展示成功: %@", rewardVideoAd);
}

- (void)WDGroMoreRewardVideoAdDidClickSkip:(nonnull BUNativeExpressRewardedVideoAd *)rewardVideoAd {
    NSLog(@"⚠️ [激励] 用户点击跳过广告: %@", rewardVideoAd);
}

- (void)WDGroMoreRewardVideoAdDidLoad:(nonnull BUNativeExpressRewardedVideoAd *)rewardVideoAd {
    NSLog(@"✅ [激励] 广告加载成功: %@", rewardVideoAd);
}

- (void)WDGroMoreRewardVideoAdDidPlayFinish:(nonnull BUNativeExpressRewardedVideoAd *)rewardVideoAd didFailWithError:(nonnull NSError *)error {
    if (error) {
        NSLog(@"❌ [激励] 播放失败: %@, 错误: %@", rewardVideoAd, error);
    } else {
        NSLog(@"✅ [激励] 播放完成: %@", rewardVideoAd);
    }
}

- (void)WDGroMoreRewardVideoAdDidShowFailed:(nonnull BUNativeExpressRewardedVideoAd *)rewardVideoAd error:(nonnull NSError *)error {
    NSLog(@"❌ [激励] 展示失败: %@，错误: %@", rewardVideoAd, error);
}

- (void)WDGroMoreRewardVideoDelegateWithClose:(nonnull BUNativeExpressRewardedVideoAd *)rewardVideoAd {
    NSLog(@"✅ [激励] 广告关闭: %@", rewardVideoAd);
}

- (void)WDGroMoreRewardedVideoAdServerRewardDidSucceed:(nonnull BUNativeExpressRewardedVideoAd *)rewardVideoAd {
    NSLog(@"🎁 [激励] 服务端验证成功，奖励发放: %@", rewardVideoAd);
}


@end
